package com.lottery.ruok.lottrey.fragment;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.activity.PrizeListActivity;
import com.lottery.ruok.lottrey.adapter.DistributionAdapter;
import com.lottery.ruok.lottrey.eventbusObject.ListToTop;
import com.lottery.ruok.lottrey.eventbusObject.Tabs;
import com.lottery.ruok.lottrey.retrofitModule.response.LotteryStatOneResponse;
import com.lottery.ruok.lottrey.ui.MyListView;
import com.nex3z.flowlayout.FlowLayout;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.HashSet;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import ui.AreaCircle;
import utils.Utils;

/**
 * Created by ASUS on 2017/7/27.
 */

public class DistributionFragment extends BaseFragment {
    @BindView(R.id.he_daxiao)
    TextView heDaxiao;
    @BindView(R.id.container)
    FlowLayout container;
    @BindView(R.id.dan)
    TextView dan;
    @BindView(R.id.shuang)
    TextView shuang;
    @BindView(R.id.da)
    TextView da;
    @BindView(R.id.xiao)
    TextView xiao;
    @BindView(R.id.listView)
    MyListView listView;
    @BindView(R.id.danshuang_divider)
    View danshuang_divider;
    @BindView(R.id.daxiao_divider1)
    View daxiao_divider1;
    @BindView(R.id.daxiao_divider2)
    View daxiao_divider2;//逻辑有点复杂，到时候可以优化

    private DistributionAdapter myAdapter;
    private int isDanChoose = 0;//0是未选中，1是选中
    private int isShuangChoose = 0;
    private int isDaChoose = 0;
    private int isXiaoChoose = 0;
    private int isHeChoose = 0;
    private HashSet<String> chooseNumbers = new HashSet<>();
    private String[] nums;
    private int chosenBallCount = 0;//选中小球的数量
    private LotteryStatOneResponse data;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.number_distribution_fragment, container, false);

        ButterKnife.bind(this, view);

        init();
        return view;
    }

    private void init() {
        listView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView absListView, int i) {

            }

            @Override
            public void onScroll(AbsListView absListView, int i, int i1, int i2) {
                if(i > 10){
                    ((PrizeListActivity)getActivity()).gotoTop.setVisibility(View.VISIBLE);
                } else {
                    ((PrizeListActivity)getActivity()).gotoTop.setVisibility(View.GONE);
                }
            }
        });
        if(chooseNumbers != null){
            chooseNumbers.clear();
        }
        if (data != null) {
            if (data.getItem_code().equals("ctgd11x5")
                    || data.getItem_code().equals("gd11x5")
                    || data.getItem_code().equals("ctgxkl10fz")) {
                heDaxiao.setVisibility(View.VISIBLE);
                daxiao_divider1.setVisibility(View.VISIBLE);
            } else {
                heDaxiao.setVisibility(View.GONE);
                daxiao_divider1.setVisibility(View.GONE);//隐藏daxiao_divider1而选择一直显示daxiao_divider2
            }

            if (data.getNums() != null) {
                nums = data.getNums().split(",");
                for (String s : nums) {
                    final AreaCircle areaCircle = new AreaCircle(getContext());
                    areaCircle.setText(s);
                    areaCircle.setBackground(Color.parseColor("#ededed"));
                    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(Utils.dip2px(getContext(), 26), Utils.dip2px(getContext(), 26));
                    layoutParams.rightMargin = Utils.dip2px(getContext(), 7);
                    areaCircle.setLayoutParams(layoutParams);
                    container.addView(areaCircle);
                    final String t = Integer.parseInt(s) + "";
                    areaCircle.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (chosenBallCount == 0) {//如果第一个球被选中，那么进行如下操作
                                for (int i = 0; i < nums.length; i++) {
                                    int o = Integer.parseInt(nums[i]);
                                    chooseNumbers.remove(o + "");
                                }

                                setUnChoose(shuang);
                                setUnChoose(dan);
                                setUnChoose(da);
                                setUnChoose(xiao);
                                setUnChoose(heDaxiao);

                                danshuang_divider.setVisibility(View.VISIBLE);
                                daxiao_divider2.setVisibility(View.VISIBLE);
                                if (!(data.getItem_code().equals("ctgd11x5")
                                        || data.getItem_code().equals("gd11x5")
                                        || data.getItem_code().equals("ctgxkl10fz"))) {
                                    daxiao_divider1.setVisibility(View.GONE);
                                } else {
                                    daxiao_divider1.setVisibility(View.VISIBLE);
                                }

                                isShuangChoose = 0;
                                isDanChoose = 0;
                                isDaChoose = 0;
                                isXiaoChoose = 0;
                                isHeChoose = 0;
                            }
                            if (chooseNumbers.contains(t)) {
                                chooseNumbers.remove(t);
                                areaCircle.setBackground(Color.parseColor("#ededed"));

                                chosenBallCount--;
                            } else {
                                chosenBallCount++;

                                chooseNumbers.add(t);

                                if (t.equals("0")) {
                                    areaCircle.setBackground(Color.parseColor("#de625c"));
                                } else {
                                    int num = Integer.parseInt(t);
                                    switch (num % 10) {
                                        case 0:
                                            areaCircle.setBackground(Color.parseColor("#a9a5a5"));
                                            break;
                                        case 1:
                                            areaCircle.setBackground(Color.parseColor("#9076d2"));
                                            break;
                                        case 2:
                                            areaCircle.setBackground(Color.parseColor("#dba3ca"));
                                            break;
                                        case 3:
                                            areaCircle.setBackground(Color.parseColor("#8398cf"));
                                            break;
                                        case 4:
                                            areaCircle.setBackground(Color.parseColor("#7796ef"));
                                            break;
                                        case 5:
                                            areaCircle.setBackground(Color.parseColor("#83b6c3"));
                                            break;
                                        case 6:
                                            areaCircle.setBackground(Color.parseColor("#afcda5"));
                                            break;
                                        case 7:
                                            areaCircle.setBackground(Color.parseColor("#e0cd81"));
                                            break;
                                        case 8:
                                            areaCircle.setBackground(Color.parseColor("#ec9968"));
                                            break;
                                        case 9:
                                            areaCircle.setBackground(Color.parseColor("#ec6e3c"));
                                            break;
                                    }
                                }
                            }
                            areaCircle.invalidate();
                            container.invalidate();
                            myAdapter.notifyDataSetChanged();
                        }
                    });
                }
            }

            myAdapter = new DistributionAdapter(getActivity(), getActivity(), chooseNumbers);
            listView.setAdapter(myAdapter);
        }
    }

    public void getList(){
        if(myAdapter != null){
            myAdapter.notifyDataSetChanged();
        }
    }

    private void setBallCondition(){
        for(int i = 0; i < container.getChildCount(); i++){
            AreaCircle areaCircle = (AreaCircle) container.getChildAt(i);
            areaCircle.setBackground(Color.parseColor("#ededed"));
        }
    }

    @OnClick({R.id.dan, R.id.shuang, R.id.da, R.id.xiao, R.id.he_daxiao})
    public void onViewClicked(View view) {
        if(nums != null){
            switch (view.getId()) {
                case R.id.dan:
                    isShuangChoose = 0;

                    if (isDanChoose == 1) {
                        danshuang_divider.setVisibility(View.VISIBLE);
                        isDanChoose = 0;

                        setUnChoose(dan);

                        for (int i = 0; i < nums.length; i++) {
                            int o = Integer.parseInt(nums[i]);
                            if (o % 2 == 1) {
                                chooseNumbers.remove(o + "");
                            }
                        }

                        if(isDaChoose == 1) {
                            for (int i = nums.length / 2; i < nums.length; i++) {
                                if (data.getItem_code().equals("ctgd11x5")
                                        || data.getItem_code().equals("gd11x5")
                                        || data.getItem_code().equals("ctgxkl10fz")) {
                                    if (i == nums.length - 1) {
                                        continue;
                                    }
                                }
                                chooseNumbers.add(Integer.parseInt(nums[i]) + "");
                            }
                            for (int i = 0; i < nums.length / 2; i++) {
                                if (data.getItem_code().equals("ctgd11x5")
                                        || data.getItem_code().equals("gd11x5")
                                        || data.getItem_code().equals("ctgxkl10fz")) {
                                    if (i == nums.length - 1) {
                                        continue;
                                    }
                                }
                                chooseNumbers.remove(Integer.parseInt(nums[i]) + "");
                            }
                            if (data.getItem_code().equals("ctgd11x5")
                                    || data.getItem_code().equals("gd11x5")
                                    || data.getItem_code().equals("ctgxkl10fz")) {
                                chooseNumbers.remove(Integer.parseInt(nums[nums.length - 1]) + "");
                            }
                        } else if(isXiaoChoose == 1){
                            for (int i = nums.length / 2; i < nums.length; i++) {
                                if (data.getItem_code().equals("ctgd11x5")
                                        || data.getItem_code().equals("gd11x5")
                                        || data.getItem_code().equals("ctgxkl10fz")) {
                                    if(i == nums.length - 1){
                                        continue;
                                    }
                                }
                                chooseNumbers.remove(Integer.parseInt(nums[i]) + "");
                            }
                            for (int i = 0; i < nums.length / 2; i++) {
                                if (data.getItem_code().equals("ctgd11x5")
                                        || data.getItem_code().equals("gd11x5")
                                        || data.getItem_code().equals("ctgxkl10fz")) {
                                    if(i == nums.length - 1){
                                        continue;
                                    }
                                }
                                chooseNumbers.add(Integer.parseInt(nums[i]) + "");
                            }
                            if (data.getItem_code().equals("ctgd11x5")
                                    || data.getItem_code().equals("gd11x5")
                                    || data.getItem_code().equals("ctgxkl10fz")) {
                                chooseNumbers.remove(Integer.parseInt(nums[nums.length - 1]) + "");
                            }
                        } else if(isHeChoose == 1){
                            for (int i = 0; i < nums.length; i++) {
                                if (data.getItem_code().equals("ctgd11x5")
                                        || data.getItem_code().equals("gd11x5")
                                        || data.getItem_code().equals("ctgxkl10fz")) {
                                    if(i == nums.length - 1){
                                        continue;
                                    }
                                }
                                chooseNumbers.remove(Integer.parseInt(nums[i]) + "");
                            }
                            chooseNumbers.add(Integer.parseInt(nums[nums.length - 1]) + "");
                        }
                    } else {
                        chosenBallCount = 0;
                        danshuang_divider.setVisibility(View.GONE);
                        isDanChoose = 1;
                        setBallCondition();

                        setChoose(dan);
                        setUnChoose(shuang);

                        for (int i = 0; i < nums.length; i++) {
                            int o = Integer.parseInt(nums[i]);
                            if (o % 2 == 1) {
                                if(isDaChoose == 1){
                                    if (data.getItem_code().equals("ctgd11x5")
                                            || data.getItem_code().equals("gd11x5")
                                            || data.getItem_code().equals("ctgxkl10fz")) {
                                        if(i >= nums.length / 2 && i < nums.length - 1){
                                            chooseNumbers.add(o + "");
                                        } else {
                                            chooseNumbers.remove(o + "");
                                        }
                                    } else {
                                        if(i >= nums.length / 2){
                                            chooseNumbers.add(o + "");
                                        } else {
                                            chooseNumbers.remove(o + "");
                                        }
                                    }
                                } else if(isXiaoChoose == 1){
                                    if(i < nums.length / 2){
                                        chooseNumbers.add(o + "");
                                    } else {
                                        chooseNumbers.remove(o + "");
                                    }
                                } else if(isHeChoose == 1){
                                    if(i == nums.length - 1){
                                        chooseNumbers.add(o + "");
                                    } else {
                                        chooseNumbers.remove(o + "");
                                    }
                                } else {
                                    chooseNumbers.add(o + "");
                                }
                            } else {
                                chooseNumbers.remove(o + "");
                            }
                        }
                    }
                    myAdapter.notifyDataSetChanged();
                    break;
                case R.id.shuang:
                    isDanChoose = 0;
                    if (isShuangChoose == 1) {
                        danshuang_divider.setVisibility(View.VISIBLE);
                        isShuangChoose = 0;

                        setUnChoose(shuang);

                        for (int i = 0; i < nums.length; i++) {
                            int o = Integer.parseInt(nums[i]);
                            if (o % 2 == 0) {
                                chooseNumbers.remove(o + "");
                            }
                        }

                        if(isDaChoose == 1) {
                            for (int i = nums.length / 2; i < nums.length; i++) {
                                if (data.getItem_code().equals("ctgd11x5")
                                        || data.getItem_code().equals("gd11x5")
                                        || data.getItem_code().equals("ctgxkl10fz")) {
                                    if (i == nums.length - 1) {
                                        continue;
                                    }
                                }
                                chooseNumbers.add(Integer.parseInt(nums[i]) + "");
                            }
                            for (int i = 0; i < nums.length / 2; i++) {
                                if (data.getItem_code().equals("ctgd11x5")
                                        || data.getItem_code().equals("gd11x5")
                                        || data.getItem_code().equals("ctgxkl10fz")) {
                                    if (i == nums.length - 1) {
                                        continue;
                                    }
                                }
                                chooseNumbers.remove(Integer.parseInt(nums[i]) + "");
                            }
                            if (data.getItem_code().equals("ctgd11x5")
                                    || data.getItem_code().equals("gd11x5")
                                    || data.getItem_code().equals("ctgxkl10fz")) {
                                chooseNumbers.remove(Integer.parseInt(nums[nums.length - 1]) + "");
                            }
                        } else if(isXiaoChoose == 1){
                            for (int i = nums.length / 2; i < nums.length; i++) {
                                if (data.getItem_code().equals("ctgd11x5")
                                        || data.getItem_code().equals("gd11x5")
                                        || data.getItem_code().equals("ctgxkl10fz")) {
                                    if(i == nums.length - 1){
                                        continue;
                                    }
                                }
                                chooseNumbers.remove(Integer.parseInt(nums[i]) + "");
                            }
                            for (int i = 0; i < nums.length / 2; i++) {
                                if (data.getItem_code().equals("ctgd11x5")
                                        || data.getItem_code().equals("gd11x5")
                                        || data.getItem_code().equals("ctgxkl10fz")) {
                                    if(i == nums.length - 1){
                                        continue;
                                    }
                                }
                                chooseNumbers.add(Integer.parseInt(nums[i]) + "");
                            }
                            if (data.getItem_code().equals("ctgd11x5")
                                    || data.getItem_code().equals("gd11x5")
                                    || data.getItem_code().equals("ctgxkl10fz")) {
                                chooseNumbers.remove(Integer.parseInt(nums[nums.length - 1]) + "");
                            }
                        } else if(isHeChoose == 1){
                            for (int i = 0; i < nums.length; i++) {
                                if (data.getItem_code().equals("ctgd11x5")
                                        || data.getItem_code().equals("gd11x5")
                                        || data.getItem_code().equals("ctgxkl10fz")) {
                                    if(i == nums.length - 1){
                                        continue;
                                    }
                                }
                                chooseNumbers.remove(Integer.parseInt(nums[i]) + "");
                            }
                            chooseNumbers.add(Integer.parseInt(nums[nums.length - 1]) + "");
                        }
                    } else {
                        chosenBallCount = 0;
                        danshuang_divider.setVisibility(View.GONE);
                        isShuangChoose = 1;
                        setBallCondition();

                        setChoose(shuang);
                        setUnChoose(dan);

                        for (int i = 0; i < nums.length; i++) {
                            int o = Integer.parseInt(nums[i]);
                            if (o % 2 == 0) {
                                if(isDaChoose == 1){
                                    if (data.getItem_code().equals("ctgd11x5")
                                            || data.getItem_code().equals("gd11x5")
                                            || data.getItem_code().equals("ctgxkl10fz")) {
                                        if(i >= nums.length / 2 && i < nums.length - 1){
                                            chooseNumbers.add(o + "");
                                        } else {
                                            chooseNumbers.remove(o + "");
                                        }
                                    } else {
                                        if(i >= nums.length / 2){
                                            chooseNumbers.add(o + "");
                                        } else {
                                            chooseNumbers.remove(o + "");
                                        }
                                    }
                                } else if(isXiaoChoose == 1){
                                    if(i < nums.length / 2){
                                        chooseNumbers.add(o + "");
                                    } else {
                                        chooseNumbers.remove(o + "");
                                    }
                                } else if(isHeChoose == 1){
                                    if(i == nums.length - 1){
                                        chooseNumbers.add(o + "");
                                    } else {
                                        chooseNumbers.remove(o + "");
                                    }
                                } else {
                                    chooseNumbers.add(o + "");
                                }
                            } else {
                                chooseNumbers.remove(o + "");
                            }
                        }
                    }
                    myAdapter.notifyDataSetChanged();
                    break;
                case R.id.da:
                    isXiaoChoose = 0;
                    isHeChoose = 0;

                    if (isDaChoose == 1) {
                        if(heDaxiao.getVisibility() == View.VISIBLE){
                            daxiao_divider2.setVisibility(View.VISIBLE);
                            daxiao_divider1.setVisibility(View.VISIBLE);
                        } else {
                            daxiao_divider2.setVisibility(View.VISIBLE);
                        }

                        isDaChoose = 0;

                        setUnChoose(da);

                        for (int i = nums.length / 2; i < nums.length; i++) {
                            if (data.getItem_code().equals("ctgd11x5")
                                    || data.getItem_code().equals("gd11x5")
                                    || data.getItem_code().equals("ctgxkl10fz")) {
                                if(i == nums.length - 1){
                                    continue;
                                }
                            }
                            chooseNumbers.remove(Integer.parseInt(nums[i]) + "");
                        }

                        if(isDanChoose == 1){
                            for (int i = 0; i < nums.length; i++) {
                                int o = Integer.parseInt(nums[i]);
                                if (o % 2 == 1) {
                                    chooseNumbers.add(o + "");
                                } else {
                                    chooseNumbers.remove(o + "");
                                }
                            }
                        } else if(isShuangChoose == 1){
                            for (int i = 0; i < nums.length; i++) {
                                int o = Integer.parseInt(nums[i]);
                                if (o % 2 == 0) {
                                    chooseNumbers.add(o + "");
                                } else {
                                    chooseNumbers.remove(o + "");
                                }
                            }
                        }
                    } else {
                        if(heDaxiao.getVisibility() == View.VISIBLE){
                            daxiao_divider2.setVisibility(View.VISIBLE);
                            daxiao_divider1.setVisibility(View.GONE);
                        } else {
                            daxiao_divider2.setVisibility(View.GONE);
                        }

                        chosenBallCount = 0;
                        setBallCondition();
                        isDaChoose = 1;

                        setChoose(da);
                        setUnChoose(xiao);
                        setUnChoose(heDaxiao);

                        for (int i = nums.length / 2; i < nums.length; i++) {
                            if (data.getItem_code().equals("ctgd11x5")
                                    || data.getItem_code().equals("gd11x5")
                                    || data.getItem_code().equals("ctgxkl10fz")) {
                                if(i == nums.length - 1){
                                    continue;
                                }
                            }
                            if(isDanChoose == 1){
                                int o = Integer.parseInt(nums[i]);
                                if(o % 2 == 1){
                                    chooseNumbers.add(o + "");
                                } else {
                                    chooseNumbers.remove(o + "");
                                }
                            } else if(isShuangChoose == 1){
                                int o = Integer.parseInt(nums[i]);
                                if(o % 2 == 0){
                                    chooseNumbers.add(o + "");
                                } else {
                                    chooseNumbers.remove(o + "");
                                }
                            } else {
                                chooseNumbers.add(Integer.parseInt(nums[i]) + "");
                            }
                        }
                        for (int i = 0; i < nums.length / 2; i++) {
                            if (data.getItem_code().equals("ctgd11x5")
                                    || data.getItem_code().equals("gd11x5")
                                    || data.getItem_code().equals("ctgxkl10fz")) {
                                if(i == nums.length - 1){
                                    continue;
                                }
                            }
                            chooseNumbers.remove(Integer.parseInt(nums[i]) + "");
                        }
                        if (data.getItem_code().equals("ctgd11x5")
                                || data.getItem_code().equals("gd11x5")
                                || data.getItem_code().equals("ctgxkl10fz")) {
                            chooseNumbers.remove(Integer.parseInt(nums[nums.length - 1]) + "");
                        }
                    }
                    myAdapter.notifyDataSetChanged();
                    break;
                case R.id.xiao:
                    isDaChoose = 0;
                    isHeChoose = 0;

                    if (isXiaoChoose == 1) {
                        if(heDaxiao.getVisibility() == View.VISIBLE){
                            daxiao_divider2.setVisibility(View.VISIBLE);
                            daxiao_divider1.setVisibility(View.VISIBLE);
                        } else {
                            daxiao_divider2.setVisibility(View.VISIBLE);
                        }

                        isXiaoChoose = 0;

                        setUnChoose(xiao);

                        for (int i = 0; i < nums.length / 2; i++) {
                            if (data.getItem_code().equals("ctgd11x5")
                                    || data.getItem_code().equals("gd11x5")
                                    || data.getItem_code().equals("ctgxkl10fz")) {
                                if(i == nums.length - 1){
                                    continue;
                                }
                            }
                            chooseNumbers.remove(Integer.parseInt(nums[i]) + "");
                        }

                        if(isDanChoose == 1){
                            for (int i = 0; i < nums.length; i++) {
                                int o = Integer.parseInt(nums[i]);
                                if (o % 2 == 1) {
                                    chooseNumbers.add(o + "");
                                } else {
                                    chooseNumbers.remove(o + "");
                                }
                            }
                        } else if(isShuangChoose == 1){
                            for (int i = 0; i < nums.length; i++) {
                                int o = Integer.parseInt(nums[i]);
                                if (o % 2 == 0) {
                                    chooseNumbers.add(o + "");
                                } else {
                                    chooseNumbers.remove(o + "");
                                }
                            }
                        }
                    } else {
                        if(heDaxiao.getVisibility() == View.VISIBLE){
                            daxiao_divider2.setVisibility(View.GONE);
                            daxiao_divider1.setVisibility(View.VISIBLE);
                        } else {
                            daxiao_divider2.setVisibility(View.GONE);
                        }

                        chosenBallCount = 0;
                        setBallCondition();
                        isXiaoChoose = 1;

                        setChoose(xiao);
                        setUnChoose(da);
                        setUnChoose(heDaxiao);

                        for (int i = nums.length / 2; i < nums.length; i++) {
                            if (data.getItem_code().equals("ctgd11x5")
                                    || data.getItem_code().equals("gd11x5")
                                    || data.getItem_code().equals("ctgxkl10fz")) {
                                if(i == nums.length - 1){
                                    continue;
                                }
                            }
                            chooseNumbers.remove(Integer.parseInt(nums[i]) + "");
                        }
                        for (int i = 0; i < nums.length / 2; i++) {
                            if (data.getItem_code().equals("ctgd11x5")
                                    || data.getItem_code().equals("gd11x5")
                                    || data.getItem_code().equals("ctgxkl10fz")) {
                                if(i == nums.length - 1){
                                    continue;
                                }
                            }
                            if(isDanChoose == 1){
                                int o = Integer.parseInt(nums[i]);
                                if(o % 2 == 1){
                                    chooseNumbers.add(o + "");
                                } else {
                                    chooseNumbers.remove(o + "");
                                }
                            } else if(isShuangChoose == 1){
                                int o = Integer.parseInt(nums[i]);
                                if(o % 2 == 0){
                                    chooseNumbers.add(o + "");
                                } else {
                                    chooseNumbers.remove(o + "");
                                }
                            } else {
                                chooseNumbers.add(Integer.parseInt(nums[i]) + "");
                            }
                        }
                        if (data.getItem_code().equals("ctgd11x5")
                                || data.getItem_code().equals("gd11x5")
                                || data.getItem_code().equals("ctgxkl10fz")) {
                            chooseNumbers.remove(Integer.parseInt(nums[nums.length - 1]) + "");
                        }
                    }
                    myAdapter.notifyDataSetChanged();
                    break;
                case R.id.he_daxiao:
                    isDaChoose = 0;
                    isXiaoChoose = 0;

                    if (isHeChoose == 1) {
                        daxiao_divider2.setVisibility(View.VISIBLE);
                        daxiao_divider1.setVisibility(View.VISIBLE);

                        isHeChoose = 0;

                        setUnChoose(heDaxiao);

                        chooseNumbers.remove(Integer.parseInt(nums[nums.length - 1]) + "");

                        if(isDanChoose == 1){
                            for (int i = 0; i < nums.length; i++) {
                                int o = Integer.parseInt(nums[i]);
                                if (o % 2 == 1) {
                                    chooseNumbers.add(o + "");
                                } else {
                                    chooseNumbers.remove(o + "");
                                }
                            }
                        } else if(isShuangChoose == 1){
                            for (int i = 0; i < nums.length; i++) {
                                int o = Integer.parseInt(nums[i]);
                                if (o % 2 == 0) {
                                    chooseNumbers.add(o + "");
                                } else {
                                    chooseNumbers.remove(o + "");
                                }
                            }
                        }
                    } else {
                        daxiao_divider2.setVisibility(View.GONE);
                        daxiao_divider1.setVisibility(View.GONE);

                        isHeChoose = 1;
                        chosenBallCount = 0;
                        setBallCondition();

                        setUnChoose(xiao);
                        setUnChoose(da);
                        setChoose(heDaxiao);

                        for (int i = 0; i < nums.length; i++) {
                            if (data.getItem_code().equals("ctgd11x5")
                                    || data.getItem_code().equals("gd11x5")
                                    || data.getItem_code().equals("ctgxkl10fz")) {
                                if(i == nums.length - 1){
                                    continue;
                                }
                            }
                            chooseNumbers.remove(Integer.parseInt(nums[i]) + "");
                        }
                        if(isDanChoose == 1){
                            int o = Integer.parseInt(nums[nums.length - 1]);
                            if(o % 2 == 1){
                                chooseNumbers.add(o + "");
                            } else {
                                chooseNumbers.remove(o + "");
                            }
                        } else if(isShuangChoose == 1){
                            int o = Integer.parseInt(nums[nums.length - 1]);
                            if(o % 2 == 0){
                                chooseNumbers.add(o + "");
                            } else {
                                chooseNumbers.remove(o + "");
                            }
                        } else {
                            chooseNumbers.add(Integer.parseInt(nums[nums.length - 1]) + "");
                        }
                    }
                    myAdapter.notifyDataSetChanged();
                    break;
            }
        }
    }

    private void setChoose(TextView textView) {
        textView.setBackgroundResource(R.drawable.bg_corners_2);
        textView.setTextColor(Color.parseColor("#ffffff"));
    }

    private void setUnChoose(TextView textView) {
        textView.setBackgroundResource(0);
        textView.setTextColor(Color.parseColor("#3f3f3f"));
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void setTabs(Tabs tabs) {
        if (tabs.isCanListScroll()) {
            listView.setCanListScroll(true);
        } else {
            listView.setCanListScroll(false);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void gotoTop(ListToTop listToTop){
        listView.setSelection(0);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        EventBus.getDefault().register(this);
    }

    @Override
    public void onDetach() {
        super.onDetach();
        EventBus.getDefault().unregister(this);
    }

    public void setData(LotteryStatOneResponse data) {
        this.data = data;
        getList();
    }
}